<?php

namespace Kunfeng\Dify\Model\Workflow;

use Kunfeng\Dify\Model\Common\Usage;

/**
 * 工作流运行响应模型
 */
class WorkflowRunResponse
{
    private $taskId;
    private $data;
    private $workflowRunId;
    private $usage;

    public function __construct(array $data)
    {
        $this->taskId = $data['task_id'] ?? '';
        $this->data = $data['data'] ?? null;
        $this->workflowRunId = $data['workflow_run_id'] ?? '';
        $this->usage = isset($data['usage']) ? Usage::fromArray($data['usage']) : null;
    }

    /**
     * 从数组创建
     */
    public static function fromArray(array $data): self
    {
        return new self($data);
    }

    // Getters
    public function getTaskId(): string
    {
        return $this->taskId;
    }

    public function getData(): ?WorkflowData
    {
        return $this->data ? WorkflowData::fromArray($this->data) : null;
    }

    public function getWorkflowRunId(): string
    {
        return $this->workflowRunId;
    }

    public function getUsage(): ?Usage
    {
        return $this->usage;
    }
}

/**
 * 工作流数据模型
 */
class WorkflowData
{
    private $outputs;
    private $nodeId;
    private $title;
    private $data;

    public function __construct(array $data)
    {
        $this->outputs = $data['outputs'] ?? [];
        $this->nodeId = $data['node_id'] ?? '';
        $this->title = $data['title'] ?? '';
        $this->data = $data['data'] ?? [];
    }

    /**
     * 从数组创建
     */
    public static function fromArray(array $data): self
    {
        return new self($data);
    }

    // Getters
    public function getOutputs(): array
    {
        return $this->outputs;
    }

    public function getNodeId(): string
    {
        return $this->nodeId;
    }

    public function getTitle(): string
    {
        return $this->title;
    }

    public function getData(): array
    {
        return $this->data;
    }
}